<template>
  <div>
    <el-row :gutter="20">
      <el-col :span="12">
        <BreakSpace label="基本信息" :containerStyle="{ marginBottom: '10px' }"></BreakSpace>
        <div>
          <FormPanel ref="formPanel" :list="formList" :cols="5" :labelWidth="110" :isSubmitBtn="false" @formChange="formChangeHandle" />
        </div>
      </el-col>
      <el-col :span="12">
        <BreakSpace label="库存" :containerStyle="{ marginBottom: '10px' }"></BreakSpace>
        <div>
          <FormPanel ref="formPanel1" :list="formList1" :cols="4" :labelWidth="80" :isSubmitBtn="false" @formChange="formChangeHandle1" />
        </div>
      </el-col>
    </el-row>
    <el-row :gutter="20">
      <el-col :span="12">
        <BreakSpace label="价格" :containerStyle="{ marginBottom: '10px' }"></BreakSpace>
        <div>
          <FormPanel ref="formPanel2" :list="formList2" :cols="4" :labelWidth="110" :isSubmitBtn="false" @formChange="formChangeHandle2" />
        </div>
      </el-col>
      <el-col :span="12">
        <BreakSpace label="其他" :containerStyle="{ marginBottom: '10px' }"></BreakSpace>
        <div>
          <FormPanel ref="formPanel3" :list="formList3" :cols="4" :labelWidth="80" :isSubmitBtn="false" @formChange="formChangeHandle3" />
        </div>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24">
        <BreakSpace label="分类" :containerStyle="{ marginBottom: '10px' }"></BreakSpace>
        <div>
          <FormPanel ref="formPanel4" :list="formList4" :cols="4" :labelWidth="110" :isSubmitBtn="false" @formChange="formChangeHandle4" />
        </div>
      </el-col>
    </el-row>
    <!-- 车型选择弹窗 -->
    <BaseDialog :visible.sync="modelSelectVisible" title="选择车型" :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <modelSelect @close="modelSelectVisible = false" @onConfirm="handleBrandSelectConfirm" />
    </BaseDialog>
  </div>
</template>

<script>
import { addPartInfo, ModifyPartInfo, queryUnitCode, queryPackUnit, getAllModel } from '@/api/part/partInfo';
import { getPinpSelect } from '@/api/repair/repairReception/customer/brand.js';
import { getToken, getAppId } from '@/assets/js/auth';
import { dictionary } from '@/utils/dictMixin';
import { getBrandAll, queryTex } from '@/api/part/common';
import { getSeriesData, getModelData, getBrandList } from '@/api/common/cars/brandcarsModels';
import { notifyAction } from '@/utils';
import { exportExcelFile, arrayObjDeWeight } from '@/utils/index';
import partModel from './partModel';
import modelSelect from './modelSelect';

// let pinyin = require('js-pinyin');
// pinyin.setOptions({ checkPolyphone: false, charCase: 0 });
import pinyin, { STYLE_FIRST_LETTER } from '@/components/Pinyin/index';
import { getChexSelect, getCheModelSelect } from '@/api/repair/repairReception/customer';

export default {
  name: 'createPart',
  components: {
    partModel,
    modelSelect
  },
  mixins: [dictionary],
  props: {
    type: {
      type: String,
      default: 'add'
    },
    rowData: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    this.conf = { add: '保 存', edit: '修 改', show: '明细' };
    this.saveData = null;
    return {
      pateVehicleModel: '',
      ismonitoring: false,
      formList: this.createFormList(),
      formList1: this.createFormList1(),
      formList2: this.createFormList2(),
      formList3: this.createFormList3(),
      formList4: this.createFormList4(),
      confirmBtnLoading: false,
      brandId: '',
      querySeriesId: '', // 选中的车系id(用于查询)
      modelSelectVisible: false, // 是否显示车型弹窗
      modelSelectData: {},
      tax: 0
    };
  },
  computed: {
    btnText() {
      return this.conf[this.type];
    }
  },
  watch: {
    rowData: {
      handler(newVal, oldVal) {
        this.saveData = newVal;
        console.log('n:', newVal);
        console.log('o:', oldVal);
        console.log('befformList:::', this.formList);
        this.formList.forEach(x => {
          if (x.fieldName != 'brand') {
            x.initialValue = newVal[x.fieldName];
          } else {
            x.initialValue = getAppId();
          }
        });
        console.log('formList:::', this.formList);
        this.formList1.forEach(x => {
          x.initialValue = newVal[x.fieldName];
        });
        this.formList2.forEach(x => {
          x.initialValue = newVal[x.fieldName];
        });
        this.formList3.forEach(x => {
          x.initialValue = newVal[x.fieldName];
        });
        this.formList4.forEach(x => {
          x.initialValue = newVal[x.fieldName];
        });
        this.saveData.createdAt = null;
        this.saveData.updatedAt = null;
        this.saveData.createdBy = null;
        this.saveData.updatedBy = null;
        this.default1();
        this.calculateV();
      },
      deep: true
    }
    // type: {
    //   handler(newVal, oldVal) {
    //     this.default1();
    //   },
    //   deep: true
    // }
  },
  created() {
    // this.init();
    // this.getBrand();
    this.getUnit();
    // this.queryPackUnitList();
    // 编辑初始化
    if (this.rowData.brand) {
      // this.getSeries(this.rowData.brandId);
    }
    // if (this.rowData.series) {
    //   this.getModel(this.rowData.series);
    // }
  },
  mounted() {
    this.default1();
    this.getAllModel();
  },
  methods: {
    init() {
      if (this.type !== 'add') {
        // 更新接口需要的记录 ID 编辑赋值
        this.recordId = this.rowData.partNo;
        let transitionList = ['partSortCode', 'packageUnit']; // 需要手动转换为数字类型的select数据回显值
        this.formList.forEach(x => {
          if (transitionList.indexOf(x.fieldName) > -1) {
            x.initialValue = this.rowData[x.fieldName] * 1;
          } else {
            x.initialValue = this.rowData[x.fieldName];
          }
        });
        this.formList.find(item => item.fieldName == 'partNo').disabled = true;
        this.queryModelName(this.rowData.series, this.rowData.model);

        // 原厂件禁用abc是否附件字段编辑
        // if (this.rowData.downTag == 10041001) {
        //   this.formList.find(item => item.fieldName == 'abcType').disabled = true;
        //   this.formList.find(item => item.fieldName == 'isAccessory').disabled = true;
        // }
      } else if (this.type == 'add' && this.rowData.partNo) {
        this.formList.forEach(x => {
          x.initialValue = this.rowData[x.fieldName];
        });
      }
      this.calculateV();
    },
    createFormList() {
      return [
        {
          type: 'INPUT',
          label: '品牌',
          fieldName: 'brand',
          placeholder: '请选择',
          initialValue: getAppId(),
          disabled: true,
          change: val => {
            this.changeBrandSelect(val);
          },
          rules: [{ required: true, message: '请选择品牌', trigger: 'change' }]
        },
        {
          type: 'TEXT_AREA',
          label: '配件代码',
          fieldName: 'partNo',
          selfCols: 2,
          initialValue: '',
          disabled: true,
          placeholder: '请输入...',
          maxlength: 18,
          // rules: [{ required: true, message: '请输入配件代码', trigger: 'blur' }]
          rules: [
            { required: true, validator: this.checkPartNo, trigger: 'blur', message: '请正确输入配件代码' },
            { pattern: /^WG-/, message: '自建请以"WG-"开头', trigger: 'blur' },
            { pattern: /^...[0-9a-zA-Z_]{1,}$/, message: '配件代码只能存在字母,数字,下划线', trigger: 'blur' }
          ]
        },
        // {
        //   type: 'INPUT',
        //   label: '配件名称',
        //   fieldName: 'partDescription',
        //   disabled: true
        // },
        {
          type: 'INPUT',
          label: '配件名称',
          fieldName: 'partName',
          disabled: true,
          initialValue: '',
          selfCols: 2,
          placeholder: '请输入...',
          rules: [{ required: true, message: '请输入配件说明', trigger: 'blur' }]
        },

        // {
        //   type: 'INPUT_NUMBER',
        //   isControls: false,
        //   label: '安全库存',
        //   fieldName: 'safeStock',
        //   precision: 2,
        //   placeholder: '请输入...',
        //   rules: [{ required: false, message: '请输入安全库存', trigger: 'blur' }]
        // },
        // {
        //   type: 'INPUT',
        //   label: '拼音代码',
        //   fieldName: 'spellCode',
        //   placeholder: '请输入...',
        //   initialValue: '',
        //   readonly: true,
        //   rules: [{ required: false, message: '请输入拼音代码', trigger: 'blur' }]
        // },
        // {
        //   type: 'INPUT_NUMBER',
        //   label: '储备高限',
        //   isControls: false,
        //   fieldName: 'maxStock',
        //   precision: 2,
        //   placeholder: '请输入...',
        //   rules: [{ required: false, message: '请输入最大库存', trigger: 'blur' }]
        // },
        // {
        //   type: 'INPUT_NUMBER',
        //   isControls: false,
        //   label: '储备低限',
        //   fieldName: 'minStock',
        //   precision: 2,
        //   placeholder: '请输入...',
        //   rules: [{ required: false, message: '请输入最小库存', trigger: 'blur' }]
        // },

        // {
        //   type: 'SELECT',
        //   label: '包装单位',
        //   fieldName: 'packageUnit',
        //   placeholder: '请输入...',
        //   itemList: this.createDictList('8105'),
        //   rules: [{ required: false, message: '请输入包装单位', trigger: 'blur' }]
        // },
        // {
        //   type: 'INPUT',
        //   label: '替代配件',
        //   fieldName: 'optionNo',
        //   placeholder: '请选择...',
        //   readonly: true,
        //   initialValue: '',
        //   unitRender: params => {
        //     return <el-button icon="el-icon-search" onClick={() => this.searchReplacePart()}></el-button>;
        //   }
        // },
        // {
        //   type: 'INPUT',
        //   label: '产地',
        //   fieldName: 'oriProCode',
        //   placeholder: '请输入...',
        //   rules: [{ required: false, message: '请输入产地', trigger: 'blur' }]
        // },

        // {
        //   type: 'INPUT_NUMBER',
        //   isControls: false,
        //   label: '网点价',
        //   fieldName: 'nodePrice',
        //   precision: 2,
        //   placeholder: '请输入...',
        //   rules: [{ required: false, message: '请输入网点价', trigger: 'blur' }]
        // },

        // {
        //   type: 'SELECT',
        //   label: 'ABC分类',
        //   fieldName: 'abcType',
        //   placeholder: '请选择',
        //   itemList: this.createDictList('8092'),
        //   rules: [{ required: false, message: '请选择ABC分类', trigger: 'change' }]
        // },
        // {
        //   type: 'SELECT',
        //   label: '配件分类代码',
        //   fieldName: 'partSortCode',
        //   placeholder: '请输入...',
        //   itemList: this.createDictList(8106),
        //   rules: [{ required: false, message: '请输入配件分类代码', trigger: 'blur' }]
        // },
        // {
        //   type: 'SELECT',
        //   label: '车系',
        //   fieldName: 'series',
        //   placeholder: '请输入...',
        //   change: val => {
        //     this.changeSeriesSelect(val);
        //   },
        //   itemList: [],
        //   rules: [{ required: false, message: '请输入车系', trigger: 'blur' }]
        // },

        // {
        //   type: 'INPUT_NUMBER',
        //   isControls: false,
        //   label: '含税销售单价',
        //   fieldName: 'costSalesPrice',
        //   precision: 2,
        //   placeholder: '请输入...',
        //   initialValue: 0,
        //   rules: [{ required: false, message: '请输入销售单价', trigger: 'blur' }]
        // },
        // {
        //   type: 'INPUT_NUMBER',
        //   label: '常规订单价格',
        //   isControls: false,
        //   fieldName: 'regularPrice',
        //   precision: 2,
        //   placeholder: '请输入...',
        //   // pattern: /^[1-9]{1}[0-9]*\.?([0-9]{1,2})?$/,
        //   rules: [
        //     { required: false, message: '请输入常规订单价格', trigger: 'blur' }
        //     // { pattern: /^[1-9]{1}[0-9]*(\.[0-9]{1,2})?$/, message: '请输入正确的价格', trigger: 'blur' }
        //   ]
        // },
        // {
        //   type: 'INPUT_NUMBER',
        //   isControls: false,
        //   label: '销售限价',
        //   fieldName: 'limitPrice',
        //   precision: 2,
        //   placeholder: '请输入...',
        //   rules: [{ required: false, message: '请输入销售限价', trigger: 'blur' }]
        // },
        // {
        //   type: 'INPUT_NUMBER',
        //   isControls: false,
        //   label: '含税批发单价',
        //   fieldName: 'costWholesalesPrice',
        //   precision: 2,
        //   placeholder: '请输入...',
        //   rules: [{ required: false, message: '请输入批发单价', trigger: 'blur' }]
        // },
        // {
        //   type: 'INPUT_NUMBER',
        //   isControls: false,
        //   label: '含税出库单价',
        //   fieldName: 'costOutPrice',
        //   precision: 2,
        //   placeholder: '请输入...',
        //   rules: [{ required: false, message: '请输入出库单价', trigger: 'blur' }]
        // },

        // {
        //   type: 'INPUT_NUMBER',
        //   isControls: false,
        //   label: '终端建议零售价格',
        //   fieldName: 'insurancePrice',
        //   precision: 2,
        //   placeholder: '请输入...',
        //   rules: [{ required: false, message: '请输入终端建议零售价格', trigger: 'blur' }]
        // },

        // {
        //   type: 'SELECT',
        //   label: '激活停用',
        //   fieldName: 'isActivate',
        //   placeholder: '请选择',
        //   itemList: this.createDictList('8131'),
        //   change: e => {
        //     if (e == 81311002) {
        //       this.formList.find(item => item.fieldName == 'activateDate').initialValue = new Date();
        //     } else {
        //       this.formList.find(item => item.fieldName == 'activateDate').initialValue = '';
        //     }
        //   },
        //   rules: [{ required: false, message: '请选择激活停用', trigger: 'change' }]
        // },

        // {
        //   type: 'CHECKBOX',
        //   label: '成套件',
        //   fieldName: 'isKitPart',
        //   options: {
        //     trueValue: 10041001,
        //     falseValue: 10041002
        //   },
        //   rules: [{ required: false, message: '请选择成套件', trigger: 'change' }],
        //   selfCols: 0.5
        // },
        // {
        //   type: 'CHECKBOX',
        //   label: '是否附件',
        //   fieldName: 'isAccessory',
        //   options: {
        //     trueValue: 10041001,
        //     falseValue: 10041002
        //   },
        //   rules: [{ required: false, message: '请选择是否附件', trigger: 'change' }],
        //   selfCols: 0.5
        // },
        // {
        //   type: 'CHECKBOX',
        //   label: '套餐',
        //   fieldName: 'isPackage',
        //   options: {
        //     trueValue: 10041001,
        //     falseValue: 10041002
        //   },
        //   rules: [{ required: false, message: '请选择套餐', trigger: 'change' }],
        //   selfCols: 0.5
        // },
        // {
        //   type: 'CHECKBOX',
        //   label: '二维码激活',
        //   fieldName: 'qrActive',
        //   options: {
        //     trueValue: 10041001,
        //     falseValue: 10041002
        //   },
        //   rules: [{ required: false, message: '请选择二维码激活', trigger: 'change' }],
        //   selfCols: 0.5
        // },
        // {
        //   type: 'CHECKBOX',
        //   label: '常用件',
        //   fieldName: 'isCommonPart',
        //   options: {
        //     trueValue: 10041001,
        //     falseValue: 10041002
        //   },
        //   rules: [{ required: false, message: '请选择常用件', trigger: 'change' }],
        //   selfCols: 0.5
        // },
        // {
        //   type: 'CHECKBOX',
        //   label: 'FIB标识',
        //   fieldName: 'fibMark',
        //   disabled: true,
        //   options: {
        //     trueValue: 'X',
        //     falseValue: 0
        //   },
        //   selfCols: 0.5
        // },

        // {
        //   type: 'SELECT',
        //   label: '九大类',
        //   fieldName: 'partMainType',
        //   placeholder: '请选择',
        //   itemList: this.createDictList('8094'),
        //   rules: [{ required: false, message: '请选择九大类', trigger: 'change' }]
        // },

        {
          type: 'CHECKBOX',
          label: '是否停用',
          fieldName: 'partStatus',
          initialValue: '10041001',
          disabled: true,
          options: {
            trueValue: '10041002',
            falseValue: '10041001'
          }
        }
        // {
        //   type: 'DATE',
        //   label: '停用时间',
        //   fieldName: 'disableDate',
        //   valueFormat: 'yyyy-MM-dd',
        //   initialValue: '',
        //   disabled: true
        //   // rules: [{ required: true, message: '激活停用时间', trigger: 'change' }]
        // },
        // {
        //   type: 'SELECT',
        //   label: 'CCC件',
        //   fieldName: 'isCccPart',
        //   placeholder: '请选择',
        //   itemList: this.createDictList('8099'),
        //   disabled: true,
        //   rules: [{ required: false, message: 'SELECT', trigger: 'change' }]
        // },
        // {
        //   type: 'INPUT',
        //   label: '体积',
        //   fieldName: 'volume',
        //   placeholder: '请输入...',
        //   disabled: true,
        //   rules: [{ required: false, message: '请输入体积', trigger: 'blur' }]
        // },
        // {
        //   type: 'INPUT',
        //   label: '体积单位',
        //   fieldName: 'volumeUnit',
        //   placeholder: '请输入...',
        //   disabled: true,
        //   rules: [{ required: false, message: '体积单位', trigger: 'blur' }]
        // },
        // {
        //   type: 'SELECT',
        //   label: '体积标识',
        //   fieldName: 'volumeMark',
        //   placeholder: '请选择',
        //   itemList: this.createDictList('1004'),
        //   disabled: true,
        //   rules: [{ required: false, message: '体积标识', trigger: 'change' }]
        // },
        // {
        //   type: 'INPUT',
        //   label: '佣金组',
        //   fieldName: 'commissGroup',
        //   placeholder: '请输入...',
        //   disabled: true,
        //   rules: [{ required: false, message: '佣金组', trigger: 'blur' }]
        // },

        // {
        //   type: 'INPUT',
        //   label: '开口件代码',
        //   fieldName: 'openCode',
        //   placeholder: '请输入...',
        //   disabled: true,
        //   rules: [{ required: false, message: '开口件代码', trigger: 'blur' }]
        // },
        // {
        //   type: 'SELECT',
        //   label: '新能源标识',
        //   fieldName: 'isEnergy',
        //   placeholder: '请选择',
        //   itemList: this.createDictList('1004'),
        //   disabled: true,
        //   rules: [{ required: false, message: '新能源标识', trigger: 'change' }]
        // },

        // {
        //   type: 'INPUT',
        //   label: '重量单位',
        //   fieldName: 'weightUnit',
        //   placeholder: '请输入...',
        //   disabled: true,
        //   rules: [{ required: false, message: '重量单位', trigger: 'blur' }]
        // },
        // {
        //   type: 'SELECT',
        //   label: '重量标识',
        //   fieldName: 'weightMark',
        //   placeholder: '请选择',
        //   itemList: this.createDictList('1004'),
        //   disabled: true,
        //   rules: [{ required: false, message: '重量标识', trigger: 'change' }]
        // },

        // {
        //   type: 'INPUT',
        //   label: '维修电动汽车标识',
        //   fieldName: 'repairVehicleMark',
        //   disabled: true
        // },
        // {
        //   type: 'CHECKBOX',
        //   label: '保质期标识',
        //   fieldName: 'shelfLiftMark',
        //   disabled: true,
        //   options: {
        //     trueValue: '1',
        //     falseValue: '0'
        //   },
        //   selfCols: 0.5
        // },
        // {
        //   type: 'CHECKBOX',
        //   label: '是否在EOP',
        //   fieldName: 'isEop',
        //   disabled: true,
        //   options: {
        //     trueValue: 'x',
        //     falseValue: 0
        //   },
        //   selfCols: 0.5
        // },
        // {
        //   type: 'CHECKBOX',
        //   label: '采购锁标识',
        //   fieldName: 'stockLockMark',
        //   disabled: true,
        //   options: {
        //     trueValue: '1',
        //     falseValue: '0'
        //   },
        //   selfCols: 0.5
        // },
        // {
        //   type: 'CHECKBOX',
        //   label: '销售锁标识',
        //   fieldName: 'saleLockMark',
        //   disabled: true,
        //   options: {
        //     trueValue: '1',
        //     falseValue: '0'
        //   },
        //   selfCols: 0.5
        // },
        // {
        //   type: 'CHECKBOX',
        //   label: '仅辖区库发货标识',
        //   fieldName: 'shipMark',
        //   disabled: true,
        //   options: {
        //     trueValue: 'x',
        //     falseValue: 0
        //   },
        //   selfCols: 0.5
        // },
        // {
        //   type: 'CHECKBOX',
        //   label: '个性化件',
        //   fieldName: 'personOrderMark',
        //   disabled: true,
        //   options: {
        //     trueValue: 'X',
        //     falseValue: 0
        //   },
        //   selfCols: 0.5
        // },
        // {
        //   type: 'CHECKBOX',
        //   label: '三方订单件',
        //   fieldName: 'thirdOrderMark',
        //   disabled: true,
        //   options: {
        //     trueValue: 'X',
        //     falseValue: 0
        //   },
        //   selfCols: 0.5
        // },

        // {
        //   type: 'INPUT',
        //   label: '加价组',
        //   fieldName: 'groupMark',
        //   disabled: true
        // }
      ];
    },
    createFormList2() {
      return [
        {
          type: 'INPUT_NUMBER',
          isControls: false,
          label: '终端建议零售VIP价格',
          fieldName: 'notTaxInstructPrice',
          precision: 2,
          placeholder: '请输入...',
          disabled: true,
          rules: [{ required: true, message: '请输入终端建议零售VIP价格', trigger: 'blur' }]
        },

        {
          type: 'INPUT_NUMBER',
          isControls: false,
          label: '常规订货价',
          fieldName: 'planPrice',
          disabled: true,
          precision: 2,
          placeholder: '请输入...',
          rules: [{ required: true, message: '请输入常规订货价', trigger: 'blur' }],
          change: e => {
            this.$nextTick(() => {
              this.reComputedsalerPrice();
            });
          }
        },
        {
          type: 'INPUT_NUMBER',
          isControls: false,
          label: '终端建议零售价格',
          fieldName: 'insurancePrice',
          disabled: true,
          precision: 2,
          placeholder: '请输入...',
          rules: [{ required: true, message: '请输入终端建议零售价格', trigger: 'blur' }]
        },
        {
          type: 'INPUT_NUMBER',
          isControls: false,
          label: '索赔价',
          disabled: true,
          fieldName: 'claimPrice',
          precision: 2,
          placeholder: '请输入...',
          rules: [{ required: true, message: '请输入索赔价', trigger: 'blur' }]
        },
        {
          type: 'INPUT_NUMBER',
          isControls: false,
          disabled: true,
          label: '费率',
          fieldName: 'priceAddRate',
          placeholder: '请输入...',
          rules: [{ required: true, message: '请输入费率', trigger: 'blur' }],
          min: 1,
          max: 100,
          change: e => {
            this.$nextTick(() => {
              this.reComputedsalerPrice();
            });
          }
        }
      ];
    },
    createFormList1() {
      return [
        {
          type: 'INPUT',
          label: '账面总库存',
          fieldName: 'stockQuantity',
          initialValue: 0,
          disabled: true
        },
        {
          type: 'INPUT',
          label: '可用总库存',
          initialValue: 0,
          fieldName: 'usableQuantity',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '锁定数量',
          initialValue: 0,
          fieldName: 'lockedQuantity',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '缺料数量',
          initialValue: 0,
          fieldName: 'shortQuantity',
          disabled: true
        }
      ];
    },
    createFormList3() {
      return [
        {
          type: 'INPUT_NUMBER',
          isControls: false,
          label: '长度(mm)',
          disabled: true,
          fieldName: 'partLong',
          change: e => {
            this.$nextTick(() => {
              this.calculateV();
            });
          },
          precision: 2,
          placeholder: '请输入...'
        },
        {
          type: 'INPUT_NUMBER',
          isControls: false,
          disabled: true,
          label: '宽度(mm)',
          change: e => {
            this.$nextTick(() => {
              this.calculateV();
            });
          },
          fieldName: 'partWidth',
          precision: 2,
          placeholder: '请输入...'
        },
        {
          type: 'INPUT_NUMBER',
          isControls: false,
          disabled: true,
          label: '高度(mm)',
          change: e => {
            this.$nextTick(() => {
              this.calculateV();
            });
          },
          fieldName: 'partHeight',
          precision: 2,
          placeholder: '请输入...'
        },
        {
          type: 'INPUT_NUMBER',
          isControls: false,
          label: '体积(mm3)',
          fieldName: 'partVolum',
          disabled: true,
          precision: 2,
          placeholder: '请输入...'
        },
        {
          type: 'INPUT_NUMBER',
          isControls: false,
          label: '最小包装数',
          fieldName: 'minPackage',
          precision: 2,
          disabled: true,
          placeholder: '请输入...',
          rules: [{ required: true, message: '请输入最小包装数', trigger: 'blur' }]
        },
        {
          type: 'SELECT',
          label: '单位',
          fieldName: 'unitCode',
          placeholder: '请选择',
          disabled: true,
          itemList: [],
          rules: [{ required: true, message: '请选择单位', trigger: 'change' }]
        },
        {
          type: 'INPUT',
          label: '呆滞天数',
          fieldName: 'sluggishDays',
          placeholder: '请输入...',
          disabled: true,
          rules: [{ required: true, message: '请输入呆滞天数', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '重量(g)',
          fieldName: 'weight',
          placeholder: '请输入...',
          disabled: true,
          rules: [{ required: false, message: '重量', trigger: 'blur' }]
        }
        // {
        //   type: 'DATE',
        //   label: '创建时间',
        //   fieldName: 'createdAt',
        //   valueFormat: 'yyyy-MM-dd',
        //   initialValue: '',
        //   disabled: true
        //   // rules: [{ required: true, message: '激活停用时间', trigger: 'change' }]
        // }
      ];
    },
    createFormList4() {
      return [
        {
          type: 'SELECT',
          label: '数据来源',
          fieldName: 'downTag',
          initialValue: '10041002',
          disabled: true,
          itemList: [
            { text: '厂端下发', value: '10041001' },
            { text: '店端自建', value: '10041002' }
          ]
        },
        {
          type: 'SELECT',
          label: '配件类别',
          fieldName: 'partGroupCode',
          initialValue: 502,
          disabled: this.rowData.downTag === 10041001,
          itemList: this.createDictList('8247'),
          rules: [{ required: true, message: '请选择配件类别', trigger: 'change' }]
        },
        {
          type: 'SELECT',
          label: '适用车型',
          fieldName: 'model',
          filterable: true,
          placeholder: '请输入...',
          disabled: this.rowData.downTag === 10041001,
          itemList: [],
          readonly: true,
          initialValue: '',
          rules: [{ required: false, message: '请输入适用车型', trigger: 'blur' }]
        },
        // {
        //   type: 'SELECT',
        //   label: '车型',
        //   fieldName: 'PART_VEHICLE_MODEL',
        //   placeholder: '请选择...',
        //   initialValue: '',
        //   request: {
        //     fetchApi: getAllModel,
        //     params: {},
        //     datekey: '',
        //     valueKey: 'PART_VEHICLE_MODEL',
        //     textKey: 'PART_VEHICLE_MODEL'
        //   }
        // },
        {
          type: 'SELECT',
          label: '配件属性',
          fieldName: 'partType',
          placeholder: '请选择',
          disabled: this.rowData.downTag === 10041001,
          initialValue: 50001002,
          itemList: this.createDictList('5000'),
          rules: [{ required: true, message: '请选择配件属性', trigger: 'change' }]
        },
        {
          type: 'TEXT_AREA',
          label: '备注',
          fieldName: 'remark',
          selfCols: 3,
          maxlength: 200,
          disabled: true,
          style: { overflow: 'hidden', 'max-height': '100px', 'text-overflow': 'ellipsis', display: '-webkit-box', '-webkit-box-orient': 'vertical' }
        }
      ];
    },
    formChangeHandle(val) {
      console.log(val, 'val');
      this.val.forEach(x => {
        this.saveData[x.fieldName] = x;
      });
      console.log(this.saveData, 'saveData');
    },
    formChangeHandle1(val) {
      console.log(val, 'valformChangeHandle1');
      this.val.forEach(x => {
        this.saveData[x.fieldName] = x;
      });
      console.log(this.saveData, 'saveData');
    },
    formChangeHandle2(val) {
      console.log(val, 'val');
      this.val.forEach(x => {
        this.saveData[x.fieldName] = x;
      });
      console.log(this.saveData, 'saveData');
    },
    formChangeHandle3(val) {
      console.log(val, 'val');
      this.val.forEach(x => {
        this.saveData[x.fieldName] = x;
      });
      console.log(this.saveData, 'saveData');
    },
    formChangeHandle4(val) {
      console.log(val, 'val');
      this.val.forEach(x => {
        this.saveData[x.fieldName] = x;
      });
      console.log(this.saveData, 'saveData');
    },
    setSaveData(form, saveData) {
      let keys = Object.keys(form[1]);
      keys.forEach(x => {
        saveData[x] = form[1][x];
      });
    },
    // 点击保存
    async saveDialog() {
      let form = await this.$refs.formPanel.GET_FORM_DATA();
      let form1 = await this.$refs.formPanel1.GET_FORM_DATA();
      let form2 = await this.$refs.formPanel2.GET_FORM_DATA();
      let form3 = await this.$refs.formPanel3.GET_FORM_DATA();
      let form4 = await this.$refs.formPanel4.GET_FORM_DATA();
      if (form[0] || form1[0] || form2[0] || form3[0] || form4[0]) {
        return this.$message.warning('请填写必填项');
      } else {
        console.log('forms', form, form1, form2, form3, form4);
        this.setSaveData(form, this.saveData);
        this.setSaveData(form1, this.saveData);
        this.setSaveData(form2, this.saveData);
        this.setSaveData(form3, this.saveData);
        this.setSaveData(form4, this.saveData);
      }
      this.saveData.createdAt = null;
      this.saveData.updatedAt = null;
      this.saveData.createdBy = null;
      this.saveData.updatedBy = null;
      // this.$refs.formPanel.SUBMIT_FORM();
      // this.saveData.pateVehicleModel = this.pateVehicleModel;
      if (this.saveData !== null) {
        // if (this.saveData.maxStock < this.saveData.minStock) {
        //   this.$notify.error({ title: '提示信息', message: '配件的最大库存小于最小库存!' });
        //   return;
        // }

        // 车型提交单独处理
        // if (this.confirmBtnLoading) return;
        this.confirmBtnLoading = true;
        let res = {};
        try {
          if (this.type === 'add') {
            res = await addPartInfo(this.saveData);
          }
          if (this.type === 'edit') {
            this.saveData.id = this.rowData.id;
            res = await ModifyPartInfo(this.saveData, this.recordId);
          }
        } catch (err) {
          console.log(err, '保存失败');
        } finally {
          this.confirmBtnLoading = false;
          this.type = 'add';
          console.log('saveres::', res);
        }
        console.log('saveres::', res);
        if (res.resultCode == '200') {
          this.test();
          this.default1();
          this.$emit('search', { partNo: this.saveData.partNo, partType: this.saveData.partType });
        }
        return res.resultCode;
      }
    },
    default1() {
      let isDisabled = true;
      if (this.type == 'add') {
        this.new();
      } else {
        console.log(this.rowData.downTag, 'ssss');
        this.formList.find(item => item.fieldName == 'partNo').disabled = isDisabled;
        this.formList.find(item => item.fieldName == 'partName').disabled = isDisabled;
        this.formList.find(item => item.fieldName == 'partStatus').disabled = isDisabled;
        this.formList3.find(item => item.fieldName == 'sluggishDays').disabled = isDisabled;
        this.formList4.find(item => item.fieldName == 'remark').disabled = isDisabled;
        this.formList2.find(x => x.fieldName === 'notTaxInstructPrice').disabled = isDisabled;
        this.formList2.find(x => x.fieldName === 'planPrice').disabled = isDisabled;
        this.formList2.find(x => x.fieldName === 'insurancePrice').disabled = isDisabled;
        this.formList2.find(x => x.fieldName === 'claimPrice').disabled = isDisabled;
        this.formList2.find(x => x.fieldName === 'priceAddRate').disabled = isDisabled;
        this.formList3.find(x => x.fieldName === 'partLong').disabled = isDisabled;
        this.formList3.find(x => x.fieldName === 'partWidth').disabled = isDisabled;
        this.formList3.find(x => x.fieldName === 'partHeight').disabled = isDisabled;
        this.formList3.find(x => x.fieldName === 'minPackage').disabled = isDisabled;
        this.formList3.find(x => x.fieldName === 'unitCode').disabled = isDisabled;
        this.formList3.find(x => x.fieldName === 'weight').disabled = isDisabled;
        this.formList4.find(x => x.fieldName === 'partGroupCode').disabled = isDisabled;
        this.formList4.find(x => x.fieldName === 'model').disabled = isDisabled;
        this.formList4.find(x => x.fieldName === 'partType').disabled = isDisabled;
        this.formList.find(item => item.fieldName == 'partStatus').disabled = isDisabled;
        this.formList3.find(item => item.fieldName == 'sluggishDays').disabled = isDisabled;
        this.formList4.find(item => item.fieldName == 'remark').disabled = isDisabled;
      }
    },
    default() {
      this.formList.find(item => item.fieldName == 'brand').disabled = true;
      this.formList.find(item => item.fieldName == 'partNo').disabled = true;
      this.formList.find(item => item.fieldName == 'partName').disabled = true;
      this.formList.find(item => item.fieldName == 'partStatus').disabled = false;
      this.formList3.find(item => item.fieldName == 'sluggishDays').disabled = false;
      this.formList4.find(x => x.fieldName === 'partType').disabled = true;
      this.formList4.find(x => x.fieldName === 'partGroupCode').disabled = true;
      let isDisabled = true;
      console.log('this.rowData.downTag', this.rowData.downTag);
      let downTag = this.rowData.downTag;
      if (downTag && downTag == 10041002) {
        isDisabled = false;
      }
      console.log('isDisabled::', isDisabled);
      this.formList2.find(x => x.fieldName === 'notTaxInstructPrice').disabled = isDisabled;
      this.formList2.find(x => x.fieldName === 'planPrice').disabled = isDisabled;
      this.formList4.find(item => item.fieldName == 'remark').disabled = isDisabled;
      this.formList2.find(x => x.fieldName === 'insurancePrice').disabled = isDisabled;
      this.formList2.find(x => x.fieldName === 'claimPrice').disabled = isDisabled;
      this.formList2.find(x => x.fieldName === 'priceAddRate').disabled = isDisabled;
      this.formList3.find(x => x.fieldName === 'partLong').disabled = isDisabled;
      this.formList3.find(x => x.fieldName === 'partWidth').disabled = isDisabled;
      this.formList3.find(x => x.fieldName === 'partHeight').disabled = isDisabled;
      this.formList3.find(x => x.fieldName === 'minPackage').disabled = isDisabled;
      this.formList3.find(x => x.fieldName === 'unitCode').disabled = isDisabled;
      this.formList3.find(x => x.fieldName === 'weight').disabled = isDisabled;
      this.formList4.find(x => x.fieldName === 'model').disabled = isDisabled;
    },
    checkPartNo(rule, value, callback) {
      if (!value) {
        return callback(new Error(rule.message));
      } else {
        if (!/[\u4E00-\u9FA5]/g.test(value)) {
          callback();
        } else {
          if (value.length > 18) {
            return callback(new Error('配件代码过长'));
          }
          return callback(new Error(rule.message));
        }
      }
      callback();
    },
    // 查询所有品牌
    async getBrand() {
      const res = await getPinpSelect();
      console.log('brandres::', res);
      let brandItem = this.formList.find(x => x.fieldName === 'brand');
      brandItem.itemList = res.data.map(x => ({ text: x.brandName, value: x.brandCode + '' }));
      // 初始化车系列表
      // this.getSeries();
    },
    // 根据品牌查询车系
    async getSeries(brandId) {
      let brandItem = this.formList.find(x => x.fieldName === 'brand');
      let quertBrandId = brandId || brandItem.itemList.find(item => item.value == brandItem.initialValue) ? brandItem.itemList.find(item => item.value == brandItem.initialValue).id : false;
      if (quertBrandId == false) return;
      let res = await getSeriesData(quertBrandId);
      if (res.resultCode == 200) {
        this.formList.find(item => item.fieldName == 'series').itemList = res.data.map(item => ({ text: item.seriesName, value: item.seriesId + '' }));
      }
    },
    // 根据车系查询车型
    async getModel(seriesId) {
      let querySeriesId = seriesId || this.formList.find(x => x.fieldName === 'series').initialValue;
      const res = await getModelData(querySeriesId);
      this.formList4.find(x => x.fieldName === 'model').itemList = res.data.map(x => ({ value: x.modelId + '', text: x.modelName }));
    },
    // 翻译车型名称
    async queryModelName(seriesId, modelId) {
      if (seriesId && modelId) {
        let res = await getModelData(seriesId);
        if (res.resultCode == 200) {
          let modelItem = res.data.find(item => item.modelId == modelId);
          this.modelSelectData = {
            modelName: modelItem.modelName,
            modelId: modelItem.modelId
          };
          this.formList4.find(item => item.fieldName == 'model').initialValue = modelItem.modelName;
        }
      }
    },
    // 品牌下拉框改变时
    changeBrandSelect(brandId) {
      // console.log(brandId, '品牌改变');
      if (!brandId) return;
      // this.getSeries(brandId);
    },
    // 车系下拉框改变时
    changeSeriesSelect(seriesId) {
      this.clearFormItem(this.formList.find(x => x.fieldName === 'model'));
      this.modelSelectData = {};
      // if (!seriesId) return;
      // this.getModel(seriesId);
    },
    async getAllModel() {
      let res = await getAllModel();
      this.formList4.find(x => x.fieldName == 'model').itemList = res.data.map(x => ({ text: x.MODEL_NAME, value: x.MODEL_CODE }));
    },
    // 清空下拉框表当控件的值和下拉列表
    clearFormItem(item) {
      item.initialValue = '';
      item.itemList = [];
    },
    async getUnit() {
      const res = await queryUnitCode();
      console.log(res, 'res::');
      let data = arrayObjDeWeight(res.data, 'UNIT_CODE');
      this.formList3.find(item => item.fieldName == 'unitCode').itemList = data.map(x => ({ text: x.UNIT_NAME, value: x.UNIT_CODE }));
    },
    closeDialog(param) {
      this.$emit('close', false, param);
    },
    monitoringFun() {
      this.ismonitoring = true;
    },
    closeHandler(val) {
      if (val) {
        this.formList[10].initialValue = val.name;
        this.pateVehicleModel = val.code;
        this.formList = [...this.formList];
      }
      this.ismonitoring = false;
    },
    async test() {
      this.$notify({
        title: '成功',
        message: '成功',
        type: 'success'
      });
    },

    // 查询包装单位列表
    async queryPackUnitList() {
      let res = await queryPackUnit();
      this.formList.find(item => item.fieldName == 'packageUnit').itemList = res.data.map(item => ({ text: item.UNIT_NAME, value: item.UNIT_CODE }));
    },
    // 重新计算索赔价
    async reComputedsalerPrice() {
      let noTaxPrice = this.formList2.find(item => item.fieldName == 'planPrice').initialValue;
      let priceAddRate = this.formList2.find(item => item.fieldName == 'priceAddRate').initialValue;
      let salePriceItem = this.formList2.find(item => item.fieldName == 'claimPrice');
      // try {
      //   let res = await queryTex();
      //   this.tax = res.data || 0.13;
      // } catch (err) {
      //   console.log(err, '获取税率失败');
      // }
      console.log('重新计算销售价', noTaxPrice, priceAddRate, salePriceItem);
      if (noTaxPrice) {
        if (priceAddRate) {
          salePriceItem.initialValue = noTaxPrice * priceAddRate;
        } else {
          salePriceItem.initialValue = noTaxPrice;
        }
      }
    },
    // 点击车型选择
    selectCarModel() {
      this.modelSelectVisible = true;
    },
    calculateV() {
      this.formList3.find(x => x.fieldName == 'partVolum').initialValue =
        this.formList3.find(x => x.fieldName == 'partLong').initialValue *
        this.formList3.find(x => x.fieldName == 'partWidth').initialValue *
        this.formList3.find(x => x.fieldName == 'partHeight').initialValue;
    },
    new() {
      let isDisabled = false;
      this.formList.find(item => item.fieldName == 'brand').initialValue = getAppId();
      this.formList.find(item => item.fieldName == 'partNo').disabled = false;
      this.formList.find(item => item.fieldName == 'partName').disabled = false;
      this.formList.find(item => item.fieldName == 'partStatus').initialValue = 10041002;
      this.formList.find(item => item.fieldName == 'partStatus').disabled = true;
      this.formList3.find(item => item.fieldName == 'sluggishDays').disabled = false;
      this.formList4.find(item => item.fieldName == 'remark').disabled = false;
      this.formList2.find(x => x.fieldName === 'notTaxInstructPrice').disabled = isDisabled;
      this.formList2.find(x => x.fieldName === 'planPrice').disabled = isDisabled;
      this.formList2.find(x => x.fieldName === 'insurancePrice').disabled = isDisabled;
      this.formList2.find(x => x.fieldName === 'claimPrice').disabled = isDisabled;
      this.formList2.find(x => x.fieldName === 'priceAddRate').disabled = isDisabled;
      this.formList3.find(x => x.fieldName === 'partLong').disabled = isDisabled;
      this.formList3.find(x => x.fieldName === 'partWidth').disabled = isDisabled;
      this.formList3.find(x => x.fieldName === 'partHeight').disabled = isDisabled;
      this.formList3.find(x => x.fieldName === 'minPackage').disabled = isDisabled;
      this.formList3.find(x => x.fieldName === 'unitCode').disabled = isDisabled;
      this.formList3.find(x => x.fieldName === 'weight').disabled = isDisabled;
      this.formList4.find(x => x.fieldName === 'partGroupCode').disabled = isDisabled;
      this.formList4.find(x => x.fieldName === 'model').disabled = isDisabled;
      this.formList4.find(x => x.fieldName === 'partType').disabled = isDisabled;
      this.formList.find(item => item.fieldName == 'partStatus').disabled = true;
      this.formList3.find(item => item.fieldName == 'sluggishDays').disabled = isDisabled;
      this.formList4.find(item => item.fieldName == 'remark').disabled = isDisabled;
    },
    // 车型选择点击确定
    handleBrandSelectConfirm(e) {
      console.log(e);
      this.modelSelectData = e;
      this.formList.find(item => item.fieldName == 'model').initialValue = e.modelName;
      console.log(this.formList.find(item => item.fieldName == 'model'));
    }
  }
};
</script>

<style lang="less" scoped></style>
